package com.monscape.tag_c.supportclasses;

import net.daum.mf.map.api.MapPOIItem;
import net.daum.mf.map.api.MapPoint;
import net.daum.mf.map.api.MapPolyline;
import net.daum.mf.map.api.MapView;

import org.json.JSONObject;

import android.graphics.Color;

import com.monscape.tag_c.R;

public class DaumMapParser {
	private final int TAG_POLYLINE = 1000;
	private final int TAG_START_POI = 10000;
	private final int TAG_END_POI = 10001;
	private static DaumMapParser _instance = null;

	// Instance Control Methods
	private DaumMapParser() {

	}

	public static DaumMapParser getInstance() {
		if (_instance == null) {
			synchronized (DaumMapParser.class) {
				if (_instance == null) {
					_instance = new DaumMapParser();
				}
			}
		}
		return _instance;
	}

	// Getter Methods
	public MapPoint getCoodFromTradeName(String location) {
		MapPoint retValue = MapPoint.mapPointWithWCONGCoord(-1, -1);

		return retValue;
	}

	public MapPoint getCoodFromAddress(String location) {
		MapPoint retValue = MapPoint.mapPointWithWCONGCoord(-1, -1);

		return retValue;
	}

	public String getRouteJsonString(String startName, String endName,
			MapPoint startPoint, MapPoint endPoint) {
		String retValue = null;
		
		return retValue;
	}
	
	public int getTaxiCost(JSONObject jsonData) {
		int retValue = 0;
		
		return retValue;
	}
	
	public int getExpectedTime(JSONObject jsonData) {
		int retValue = 0;
		
		return retValue;
	}
	
	public double getDistance(JSONObject jsonData) {
		double retValue = 0;
		
		return retValue;
	}
	
	// Data Methods
	public JSONObject parseMapJsonData(String jsonString) {
		JSONObject jsonObject = null;
		
		return jsonObject;
	}
	
	public void parseSearchXmlData(String xmlString, int searchType) {
		
	}
	
	public MapPoint convertKTMtoWCONG(MapPoint cood) {
		MapPoint retValue = null;
		
		return retValue;
	}

	// Map Control Methods
	public void addRoutePolyLine(MapView mapView, JSONObject jsonData) {
		MapPolyline existingPolyline = mapView.findPolylineByTag(TAG_POLYLINE);
		if (existingPolyline != null) {
			mapView.removePolyline(existingPolyline);
		}
		
		MapPolyline polyline1 = new MapPolyline();
		polyline1.setTag(TAG_POLYLINE);
		polyline1.setLineColor(Color.argb(128, 255, 51, 0));						
		
		//
		// polyline1에 좌표 추가 로직 구현 
		//
		mapView.addPolyline(polyline1);
		
		mapView.fitMapViewAreaToShowPolyline(polyline1);
	}
	
	public void addStartPOIItem(MapView mapView, MapPoint startPoint) {
		MapPOIItem poiItemStart = new MapPOIItem();
		poiItemStart.setItemName("Start");
		poiItemStart.setTag(TAG_START_POI);
		poiItemStart.setMapPoint(MapPoint.mapPointWithWCONGCoord(startPoint.getMapPointWCONGCoord().x,startPoint.getMapPointWCONGCoord().y));
		poiItemStart.setMarkerType(MapPOIItem.MarkerType.CustomImage);
		poiItemStart.setShowAnimationType(MapPOIItem.ShowAnimationType.SpringFromGround);
		poiItemStart.setShowCalloutBalloonOnTouch(false);
		poiItemStart.setCustomImageResourceId(R.drawable.custom_poi_marker_start);
		poiItemStart.setCustomImageAnchorPointOffset(new MapPOIItem.ImageOffset(29,2));
		mapView.addPOIItem(poiItemStart);
	}
	
	public void addEndPOIItem(MapView mapView, MapPoint endPoint) {
		MapPOIItem poiItemEnd = new MapPOIItem();
		poiItemEnd.setItemName("End");
		poiItemEnd.setTag(TAG_END_POI);
		poiItemEnd.setMapPoint(MapPoint.mapPointWithWCONGCoord(endPoint.getMapPointWCONGCoord().x,endPoint.getMapPointWCONGCoord().y));
		poiItemEnd.setMarkerType(MapPOIItem.MarkerType.CustomImage);
		poiItemEnd.setShowAnimationType(MapPOIItem.ShowAnimationType.SpringFromGround);
		poiItemEnd.setShowCalloutBalloonOnTouch(false);
		poiItemEnd.setCustomImageResourceId(R.drawable.custom_poi_marker_end);
		poiItemEnd.setCustomImageAnchorPointOffset(new MapPOIItem.ImageOffset(29,2));
		mapView.addPOIItem(poiItemEnd);
	}
}
